{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "*__\"Half the money I spend on advertising is wasted; the trouble is I don't know which half.\"__* \n",
    "           \n",
    ">    John Wanamaker, a marketing pioneer in late 1990s and early 20th century,is reputed to have made this statement and advertisers have been wrestling with the problem ever since.<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">    In early days,many companies found it difficult to quantify the impact of various advertising channels such as newspapers,television,radio etc on their products. Though there were certain methods adopted by these companies as a solution to the problem,those methods consisted more of naive approaches rather than sophisticated and reliable techniques. In late 1990s, things started to change and the art of marketing measurements became more matured due to the influence of econometric groups with advertising agencies finding better ways to gain insights from the complex array of marketing measurements which came to be known as Marketing Mix Modelling."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# What is MMM?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Marketing Mix Modelling encompasses the method of statistical analysis such as regression on sales and marketing data to estimate the impact of various marketing tactics on sales and then predict the impact of future sets of tactics. It is also used to optimize the advertising mix and promotional tactics with respect to sales revenue or profit. Today, most brands and companies have embraced and are embracing these advanced measurement methodologies to determine the true impact of all interactions across all devices, channels, and campaign tactics. <br>\n",
    "Nowadays,most companies have a strong econometric modelling foundation with slightly varying strategies depending on their requirements,products,external competition etc."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Breaking the phrase \"Market Mix Modelling\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> On breaking the phrase,we get three words i.e Marketing,Mix and Modelling.Let's explore these terms.\n",
    "1. Marketing : This term corresponds to the understanding the market.\n",
    "2. Mix : Mix here refers to how much importance should each P be given in the 4 P(Product,price,place and promotion)\n",
    "3. Modelling : Modelling here refers to the optimization and building the model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Designing the right Marketing Mix:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The most creative & challenging step in marketing is designing the right marketing mix. The marketing mix is specific collection of actions & associated instruments employed by an organisation to stimulate acceptance of its ideas,products & services."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Final Offer to the Customer:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The final offer made to the customer or consumer is dependent on the marketing manager of the firm \n",
    "where the following four steps are followed.\n",
    "1. The firm (or the marketing manager chooses the product to meet the market demands.\n",
    "2. The right distribution channel is used to make the product available.\n",
    "3. An eye catching promotion is offered to the customer for the products.\n",
    "4. Besides promotion,appropriate price is fixed agreed by the firm and customer."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The 4 P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> A prominent marketer by name E.Jerome McCarthy proposed a four P classification in the year 1960,that has been widely used till date.\n",
    "> The four Ps can be related to the customer as follows.\n",
    "1. Product = Customer (or Consumer):\n",
    "> The first marketing-mix element is the product, which refers to the offering or group of offerings to customers. Products can be physical or virtual. In the case of a physical product, such as a bike, a company will gather information about the desired features and benefits required by a target market. Before building the product, the marketer's role is to communicate customer requirements to the engineers who design the product. This is in contrast to past practice, when engineers designed a product based on their own preferences, or expertise and the marketers had to find suitable customers to buy this product. Contemporary thinking calls for products to be designed based on customer requirements but not solely on engineers' ideas.\n",
    "> In contemporary industrialized societies, products go through life cycles: birth, growth, maturity, and decline or upgradation. This constant replacement of existing products with new or upgraded products has significant consequences for professional marketers. The development of new products involves all aspects of a business—production, finance, research and development, and even personnel administration and public relations.\n",
    "> Nowadays, some of the products are the recycled version of the same product sold in the market. This also has an impact on the brand where the resources are reused for environmental purposes.\n",
    "> Products are virtual in nature are the remote services offered by the company. For example, services offered by means of an API. Amazon Web Services offers virtualization service through it's cloud APIs.\n",
    "2. Price :\n",
    "> The second marketing-mix element is price. Ordinarily companies determine a price by gauging the competence level of the offer and then selecting a price that reflects how the market values its level of quality. However, marketers also are aware that price can send a message to a customer about the brand's reputation and product's presumed quality level. A BMW vehicle is generally considered to be a high-quality automobile. Therefore,BMW can command a high price in the market place. But, even if the brand could price its cars competitively with economy cars, it might not do so, knowing that the lower price might communicate lower quality. On the other hand, in order to gain market share, some companies have moved to “more for the same” or “the same for less” or \"cheap and best\" pricing, which means offering prices that are consistently lower than those of their competitors. This kind of discount pricing has caused firms in such industries as airlines and pharmaceuticals (which used to charge a price premium based on their past brand strength and reputation) to significantly reevaluate their marketing strategies.\n",
    "3. Place :\n",
    "> Place, or where the product is made available, is the third element of the marketing mix and is most commonly referred to as distribution. When a product moves along its path from producer to consumer, it is said to be following a channel of distribution. For example, the channel of distribution for many food products includes food-processing plants, warehouses, wholesalers, and supermarkets.\n",
    "> By using this channel, a food manufacturer makes its products easily accessible by ensuring that they are in stores that are frequented by those in the target market. In another example, a mutual funds organization makes its investment products available by enlisting the assistance of brokerage houses and banks, which in turn establish relationships with particular customers. However, each channel participant can handle only a certain number of products: space at supermarkets is limited, and investment brokers can keep abreast of only a limited number of mutual funds. Because of this, some marketers may decide to skip steps in the channel and instead market directly to buyers through direct mail, telemarketing, door-to-door selling, shopping via television (a growing trend in the late 20th century), or factory outlets.\n",
    "4. Promotion :\n",
    "> Promotion, the fourth marketing-mix element, consists of several methods of communicating with and influencing customers. The major tools are sales force, advertising, sales promotion, and public relations.\n",
    "\n",
    "  1. Sales force\n",
    "    > Sales representatives are the most expensive means of promotion, because they require income, expenses, and supplementary benefits. Their ability to personalize the promotion process makes sales people most effective at selling complex goods, big-ticket items, and highly personal goods—forexample, those related to religion or insurance. Salespeople are trained to make presentations, answer objections, gain commitments to purchase, and manage account growth. Some companies have successfully reduced their sales-force costs by replacing certain functions (for example, finding new customers) with less expensive methods (such as direct mail and telemarketing).\n",
    "\n",
    "  2. Advertising\n",
    "     > Advertising includes all forms of paid, non personal communication and promotion of products, services, or ideas by a specified sponsor. Advertising appears in such media as print (newspapers, magazines, billboards, flyers) or broadcast (radio, television). Print advertisements typically consist of a picture, a headline, information about the product, and occasionally a response coupon. Broadcast advertisements consist of an audio or video narrative that can range from short 15-second spots to longer segments known as infomercials, which generally last 30or 60 minutes.\n",
    "\n",
    "  3. Sales promotion\n",
    "     > While advertising presents a reason to buy a product, sales promotion offers a short-term incentive to purchase. Sales promotions often attract brand switchers (those who are not loyal to a specific brand) who are looking primarily for low price and good value. Thus, especially in markets where brands are highly similar, sales promotions can cause a short-term increase in sales but little permanent gain in market share. Alternatively, in markets where brands are quite dissimilar, sales promotions can alter market shares more permanently. The use of promotions has risen considerably during the late 20th century. This is due to a number of factors within companies, including an increased sophistication in sales promotion techniques and greater pressure to increase sales. Several market factors also have fostered this increase, including a rise in the number of brands (especially similar ones) and a decrease in the efficiency of traditional advertising due to increasingly fractionated consumer markets.\n",
    "\n",
    "  4. Public relations\n",
    "      > Public relations in contrast to advertising and sales promotion, generally involves less commercialized modes of communication. Its primary purpose is to disseminate information and opinion to groups and individuals who have an actual or potential impact on a company's ability to achieve its objectives. In addition, public relations specialists are responsible for monitoring these individuals and groups and for maintaining good relationships with them. One of their key activities is to work with news and information media to ensure appropriate coverage of the company's activities and products. Public relations specialists create publicity by arranging press conferences, contests, meetings, and other events that will draw attention to a company's products or services. Another public relations responsibility is crisis management—that is, handling situations in which public awareness of a particular issue may dramatically and negatively impact the company's ability to achieve its goals. For example, when it was discovered that some bottles of Perrier sparkling water might have been tainted by a harmful chemical, Source Perrier, SA's public relations team had to ensure that the general consuming public did not thereafter automatically associate Perrier with tainted water. Other public relations activities include lobbying, advising management about public issues, and planning community events.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Extension to 4 P:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "There have been attempts to develop 'extended marketing mix' to better accomodate specific aspects of marketing mix.Booms and Bitner included three additional 'Ps' to accommodatetrends towards a service or knowledge based economy.They are\n",
    "1. People\n",
    "   > All people who directly or indirectly influence the perceived value of the product or service, including knowledge workers,employees, management and consumers.\n",
    "2. Process\n",
    "   > Procedures, mechanisms and flow of activities whichlead to an exchange of value.\n",
    "3. Physical Evidence\n",
    "   > The direct sensory experience of a product or service that allows a customer to measure whether he or she has received value. Examples might include the way a customer is treated by a staff member, or the length of time a customer has to wait, or the environment in which a product or service is delivered."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Note:\n",
    "1. The term 'marketing mix' however, does not imply that the 4P elements represent options.\n",
    "2. They are not trade-offs but are fundamental marketing issues that always need to be addressed.\n",
    "3. They are the fundamental actions that marketing requires whether determined explicitly or by default.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Optimizing the marketing mix:\n",
    "> By offering the product with combination of 4 P's,the product's popularity and the sales revenue of the company selling that product will gradually increase.\n",
    "There are 2 optimizations that can be implemented.\n",
    "1. Strategic Optimization : \n",
    "   > This comes into picture when there are large changes made to the weightage given to a particular P or a group of P's. For example,a large change in price from Rs.500 to Rs.1000 might have a profound effect on the sales revenue.Such kind of changes falls under this category.\n",
    "2. Tactical Optimization :\n",
    "   > This comes into picture when there is small changes made to the weightage given to a particular P or a group of P's. For example,considering the above example for Strategic Optimization,if the Price changes from Rs.500 to Rs.499,then these kinds of changes fall under Tachtical Optimization."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Strengths and Weakness of MMM:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Though we consider market mix modelling as one of the sophisticated methods, it does have it's own strengths and weakness. Let's explore it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Strengths:\n",
    "> A successfully implemented marketing mix model can provide the following benefits:\n",
    "  1. It reflects on the past marketing decisions taken, by calculating return on investment (ROI).\n",
    "  2. It helps to optimize the marketing mix for companies by forecasting the likely impact of changes to various marketing mix variables.\n",
    "  3. It helps in finding the changes in business performance by isolating the impact of internal and external factors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Weakness:\n",
    "> \n",
    "1. The focus on short-term sales can significantly under-value the importance of longer-term equity building activities\n",
    "2. MMM used for media mix optimization, has a bias in favor of time-dependent media (such as Television) versus less time-dependent media (such as ads appearing in monthly magazines); biases can also occur when comparing broad-based media versus demographically targeted media."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " ## Working of MMM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's understand the working of MMM with an example.\n",
    "Basically, MMM's are analysed and implemented with statiscal learning algorithms such as regression.\n",
    "\n",
    "Many regression types are used in MMM for better accuracy and performance. Some of them are linear regression, multivariate regression etc."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Data set we will be working on for learning MMM is the data set used in the book 'Cutting-Edge Marketing Analytics: Real World Cases and Data Sets for Hands On Learning'. The data set is available to download from www.dmanalytics.org."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.patches as mpatches\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = pd.read_excel('MMM.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         Brand ID         Year     Absolut  Aristocrat      Barton  \\\n",
      "count  263.000000   263.000000  263.000000  263.000000  263.000000   \n",
      "mean    12.596958  2001.695817    0.049430    0.049430    0.049430   \n",
      "std      7.654584     3.639093    0.217177    0.217177    0.217177   \n",
      "min      1.000000  1995.000000    0.000000    0.000000    0.000000   \n",
      "25%      6.000000  1999.000000    0.000000    0.000000    0.000000   \n",
      "50%     12.000000  2002.000000    0.000000    0.000000    0.000000   \n",
      "75%     18.000000  2005.000000    0.000000    0.000000    0.000000   \n",
      "max     31.000000  2007.000000    1.000000    1.000000    1.000000   \n",
      "\n",
      "        Belvedere     Burnett      Chopin  Crystal Palac   Finlandia  \\\n",
      "count  263.000000  263.000000  263.000000     263.000000  263.000000   \n",
      "mean     0.026616    0.041825    0.026616       0.049430    0.049430   \n",
      "std      0.161265    0.200571    0.161265       0.217177    0.217177   \n",
      "min      0.000000    0.000000    0.000000       0.000000    0.000000   \n",
      "25%      0.000000    0.000000    0.000000       0.000000    0.000000   \n",
      "50%      0.000000    0.000000    0.000000       0.000000    0.000000   \n",
      "75%      0.000000    0.000000    0.000000       0.000000    0.000000   \n",
      "max      1.000000    1.000000    1.000000       1.000000    1.000000   \n",
      "\n",
      "           ...       LagTotalMinusSales     TierSales  OutsideTierSales  \\\n",
      "count      ...               263.000000    263.000000        263.000000   \n",
      "mean       ...             62673.935361   9547.235741      53106.615970   \n",
      "std        ...              1548.346560   2917.310122       2259.775837   \n",
      "min        ...             55687.000000    846.000000      48358.000000   \n",
      "25%        ...             62459.000000   8151.500000      51863.000000   \n",
      "50%        ...             63204.000000  10605.000000      52335.000000   \n",
      "75%        ...             63616.000000  11209.000000      54570.000000   \n",
      "max        ...             64131.000000  15790.000000      59760.000000   \n",
      "\n",
      "       LagTierSales  LagOutsideTierSales  Firstintro  Marketshare  \\\n",
      "count    263.000000           263.000000  263.000000   263.000000   \n",
      "mean    9215.528517         53458.406844    0.015209     0.046972   \n",
      "std     2946.563257          2327.430916    0.122617     0.053831   \n",
      "min      697.000000         49806.000000    0.000000     0.001468   \n",
      "25%     7493.000000         51947.000000    0.000000     0.014762   \n",
      "50%    10400.000000         52419.000000    0.000000     0.029463   \n",
      "75%    11127.500000         55392.000000    0.000000     0.053087   \n",
      "max    14299.000000         59868.000000    1.000000     0.270477   \n",
      "\n",
      "       LagMktshare      YearID      total ad  \n",
      "count   263.000000  263.000000    263.000000  \n",
      "mean      0.047470    9.695817   7386.359312  \n",
      "std       0.054685    3.639093  14280.852135  \n",
      "min       0.000971    3.000000      6.000000  \n",
      "25%       0.014655    7.000000      6.000000  \n",
      "50%       0.029181   10.000000      6.000000  \n",
      "75%       0.053633   13.000000   9691.400000  \n",
      "max       0.270477   15.000000  70489.200000  \n",
      "\n",
      "[8 rows x 66 columns]\n",
      "Index([u'BrandName', u'Brand ID', u'Year', u'Absolut', u'Aristocrat',\n",
      "       u'Barton', u'Belvedere', u'Burnett', u'Chopin', u'Crystal Palac',\n",
      "       u'Finlandia', u'Fleischmann's', u'Fris', u'Gilbey's', u'Gordon's',\n",
      "       u'Grey Goose', u'Kamchatka', u'Ketel One', u'Level', u'McCormick',\n",
      "       u'Polar Ice', u'Popov', u'Pravda', u'Seagram's', u'Skol', u'Sky',\n",
      "       u'Smirnoff', u'Stolicnaya', u'Tanqueray', u'Three Olives',\n",
      "       u'TotalSales', u'LagTotalSales', u'2LagTotalSales', u'LnSales',\n",
      "       u'LnLSales', u'Ln2Lsales', u'LnDiff', u'diff', u'IfDom', u'DollarSales',\n",
      "       u'PriceRerUnit', u'LagPrice', u'LnPrice', u'LnLPrice', u'Mag', u'News',\n",
      "       u'Outdoor', u'Broad', u'Print', u'LnMag', u'LnNews', u'LnOut',\n",
      "       u'LnBroad', u'LnPrint', u'Tier1', u'Tier2', u'TotalMinusSales',\n",
      "       u'LagTotalMinusSales', u'TierSales', u'OutsideTierSales',\n",
      "       u'LagTierSales', u'LagOutsideTierSales', u'Firstintro', u'Marketshare',\n",
      "       u'LagMktshare', u'YearID', u'total ad'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# Let's preview the data\n",
    "print data.describe()\n",
    "print data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can infer that there are a lot of columns consisting of sales ,different modes of advertising and some other variables that are not presently of our interest."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[u'Absolut' u'Aristocrat' u'Barton' u'Belvedere' u'Burnett' u'Chopin'\n",
      " u'Crystal Palac' u'Finlandia' u\"Fleischmann's\" u'Fris' u\"Gilbey's\"\n",
      " u\"Gordon's\" u'Grey Goose' u'Kamchatka' u'Ketel One' u'Level' u'McCormick'\n",
      " u'Polar Ice' u'Popov' u'Pravda' u\"Seagram's\" u'Skol' u'Sky' u'Smirnoff'\n",
      " u'Stolicnaya' u'Tanqueray' u'Three Olives']\n",
      "\n",
      "\n",
      "Total Number of brands 27\n"
     ]
    }
   ],
   "source": [
    "print data['BrandName'].unique()\n",
    "print '\\n'\n",
    "print 'Total Number of brands',len(data['BrandName'].unique())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> This data set includes a total of 27 brands of vodka manufacturing companies. For MMM, let's choose a brand and analyse the impact of Price on sales.\n",
    "  For instance, let's choose 'Absolut' as the brand for our analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>BrandName</th>\n",
       "      <th>Brand ID</th>\n",
       "      <th>Year</th>\n",
       "      <th>Absolut</th>\n",
       "      <th>Aristocrat</th>\n",
       "      <th>Barton</th>\n",
       "      <th>Belvedere</th>\n",
       "      <th>Burnett</th>\n",
       "      <th>Chopin</th>\n",
       "      <th>Crystal Palac</th>\n",
       "      <th>...</th>\n",
       "      <th>LagTotalMinusSales</th>\n",
       "      <th>TierSales</th>\n",
       "      <th>OutsideTierSales</th>\n",
       "      <th>LagTierSales</th>\n",
       "      <th>LagOutsideTierSales</th>\n",
       "      <th>Firstintro</th>\n",
       "      <th>Marketshare</th>\n",
       "      <th>LagMktshare</th>\n",
       "      <th>YearID</th>\n",
       "      <th>total ad</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>1995</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>60903</td>\n",
       "      <td>1080</td>\n",
       "      <td>59760</td>\n",
       "      <td>1035</td>\n",
       "      <td>59868</td>\n",
       "      <td>0</td>\n",
       "      <td>0.133923</td>\n",
       "      <td>0.124241</td>\n",
       "      <td>3</td>\n",
       "      <td>52343.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>1996</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>60840</td>\n",
       "      <td>1255</td>\n",
       "      <td>59277</td>\n",
       "      <td>1080</td>\n",
       "      <td>59760</td>\n",
       "      <td>0</td>\n",
       "      <td>0.142007</td>\n",
       "      <td>0.133923</td>\n",
       "      <td>4</td>\n",
       "      <td>52297.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>1997</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>60532</td>\n",
       "      <td>1532</td>\n",
       "      <td>58932</td>\n",
       "      <td>1255</td>\n",
       "      <td>59277</td>\n",
       "      <td>0</td>\n",
       "      <td>0.146758</td>\n",
       "      <td>0.142007</td>\n",
       "      <td>5</td>\n",
       "      <td>54947.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>1998</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>60464</td>\n",
       "      <td>1730</td>\n",
       "      <td>58576</td>\n",
       "      <td>1532</td>\n",
       "      <td>58932</td>\n",
       "      <td>0</td>\n",
       "      <td>0.146106</td>\n",
       "      <td>0.146758</td>\n",
       "      <td>6</td>\n",
       "      <td>57432.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>1999</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>60306</td>\n",
       "      <td>2118</td>\n",
       "      <td>57800</td>\n",
       "      <td>1730</td>\n",
       "      <td>58576</td>\n",
       "      <td>0</td>\n",
       "      <td>0.161284</td>\n",
       "      <td>0.146106</td>\n",
       "      <td>7</td>\n",
       "      <td>63213.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59918</td>\n",
       "      <td>2549</td>\n",
       "      <td>56846</td>\n",
       "      <td>2118</td>\n",
       "      <td>57800</td>\n",
       "      <td>0</td>\n",
       "      <td>0.173368</td>\n",
       "      <td>0.161284</td>\n",
       "      <td>8</td>\n",
       "      <td>70489.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2001</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59395</td>\n",
       "      <td>3358</td>\n",
       "      <td>56295</td>\n",
       "      <td>2549</td>\n",
       "      <td>56846</td>\n",
       "      <td>0</td>\n",
       "      <td>0.157546</td>\n",
       "      <td>0.173368</td>\n",
       "      <td>9</td>\n",
       "      <td>59715.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2002</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59653</td>\n",
       "      <td>4197</td>\n",
       "      <td>55392</td>\n",
       "      <td>3358</td>\n",
       "      <td>56295</td>\n",
       "      <td>0</td>\n",
       "      <td>0.150425</td>\n",
       "      <td>0.157546</td>\n",
       "      <td>10</td>\n",
       "      <td>62148.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2003</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59589</td>\n",
       "      <td>4939</td>\n",
       "      <td>54669</td>\n",
       "      <td>4197</td>\n",
       "      <td>55392</td>\n",
       "      <td>0</td>\n",
       "      <td>0.139245</td>\n",
       "      <td>0.150425</td>\n",
       "      <td>11</td>\n",
       "      <td>63602.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2004</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59608</td>\n",
       "      <td>5582</td>\n",
       "      <td>53906</td>\n",
       "      <td>4939</td>\n",
       "      <td>54669</td>\n",
       "      <td>0</td>\n",
       "      <td>0.134353</td>\n",
       "      <td>0.139245</td>\n",
       "      <td>12</td>\n",
       "      <td>66816.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2005</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59488</td>\n",
       "      <td>6346</td>\n",
       "      <td>53178</td>\n",
       "      <td>5582</td>\n",
       "      <td>53906</td>\n",
       "      <td>0</td>\n",
       "      <td>0.127440</td>\n",
       "      <td>0.134353</td>\n",
       "      <td>13</td>\n",
       "      <td>29879.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2006</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59524</td>\n",
       "      <td>7251</td>\n",
       "      <td>52094</td>\n",
       "      <td>6346</td>\n",
       "      <td>53178</td>\n",
       "      <td>0</td>\n",
       "      <td>0.124400</td>\n",
       "      <td>0.127440</td>\n",
       "      <td>14</td>\n",
       "      <td>41147.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Absolut</td>\n",
       "      <td>15</td>\n",
       "      <td>2007</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>59345</td>\n",
       "      <td>8119</td>\n",
       "      <td>51092</td>\n",
       "      <td>7251</td>\n",
       "      <td>52094</td>\n",
       "      <td>0</td>\n",
       "      <td>0.120603</td>\n",
       "      <td>0.124400</td>\n",
       "      <td>15</td>\n",
       "      <td>40280.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13 rows × 67 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   BrandName  Brand ID  Year  Absolut  Aristocrat  Barton  Belvedere  Burnett  \\\n",
       "0    Absolut        15  1995        1           0       0          0        0   \n",
       "1    Absolut        15  1996        1           0       0          0        0   \n",
       "2    Absolut        15  1997        1           0       0          0        0   \n",
       "3    Absolut        15  1998        1           0       0          0        0   \n",
       "4    Absolut        15  1999        1           0       0          0        0   \n",
       "5    Absolut        15  2000        1           0       0          0        0   \n",
       "6    Absolut        15  2001        1           0       0          0        0   \n",
       "7    Absolut        15  2002        1           0       0          0        0   \n",
       "8    Absolut        15  2003        1           0       0          0        0   \n",
       "9    Absolut        15  2004        1           0       0          0        0   \n",
       "10   Absolut        15  2005        1           0       0          0        0   \n",
       "11   Absolut        15  2006        1           0       0          0        0   \n",
       "12   Absolut        15  2007        1           0       0          0        0   \n",
       "\n",
       "    Chopin  Crystal Palac    ...     LagTotalMinusSales  TierSales  \\\n",
       "0        0              0    ...                  60903       1080   \n",
       "1        0              0    ...                  60840       1255   \n",
       "2        0              0    ...                  60532       1532   \n",
       "3        0              0    ...                  60464       1730   \n",
       "4        0              0    ...                  60306       2118   \n",
       "5        0              0    ...                  59918       2549   \n",
       "6        0              0    ...                  59395       3358   \n",
       "7        0              0    ...                  59653       4197   \n",
       "8        0              0    ...                  59589       4939   \n",
       "9        0              0    ...                  59608       5582   \n",
       "10       0              0    ...                  59488       6346   \n",
       "11       0              0    ...                  59524       7251   \n",
       "12       0              0    ...                  59345       8119   \n",
       "\n",
       "    OutsideTierSales  LagTierSales  LagOutsideTierSales  Firstintro  \\\n",
       "0              59760          1035                59868           0   \n",
       "1              59277          1080                59760           0   \n",
       "2              58932          1255                59277           0   \n",
       "3              58576          1532                58932           0   \n",
       "4              57800          1730                58576           0   \n",
       "5              56846          2118                57800           0   \n",
       "6              56295          2549                56846           0   \n",
       "7              55392          3358                56295           0   \n",
       "8              54669          4197                55392           0   \n",
       "9              53906          4939                54669           0   \n",
       "10             53178          5582                53906           0   \n",
       "11             52094          6346                53178           0   \n",
       "12             51092          7251                52094           0   \n",
       "\n",
       "    Marketshare  LagMktshare  YearID  total ad  \n",
       "0      0.133923     0.124241       3   52343.9  \n",
       "1      0.142007     0.133923       4   52297.2  \n",
       "2      0.146758     0.142007       5   54947.9  \n",
       "3      0.146106     0.146758       6   57432.7  \n",
       "4      0.161284     0.146106       7   63213.9  \n",
       "5      0.173368     0.161284       8   70489.2  \n",
       "6      0.157546     0.173368       9   59715.4  \n",
       "7      0.150425     0.157546      10   62148.3  \n",
       "8      0.139245     0.150425      11   63602.1  \n",
       "9      0.134353     0.139245      12   66816.3  \n",
       "10     0.127440     0.134353      13   29879.0  \n",
       "11     0.124400     0.127440      14   41147.4  \n",
       "12     0.120603     0.124400      15   40280.5  \n",
       "\n",
       "[13 rows x 67 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Absolut = data[data['BrandName'] == 'Absolut']\n",
    "Absolut"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are a lot of columns not of our interest. Let's filter them out."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Pr_Absolut = Absolut[['LnSales','LnPrice']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LnSales</th>\n",
       "      <th>LnPrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8.006368</td>\n",
       "      <td>4.765132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8.113726</td>\n",
       "      <td>4.707727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8.143227</td>\n",
       "      <td>4.707727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8.196988</td>\n",
       "      <td>4.750396</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8.306472</td>\n",
       "      <td>4.750397</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8.434898</td>\n",
       "      <td>4.800839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>8.384576</td>\n",
       "      <td>4.844937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.406261</td>\n",
       "      <td>4.888373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.409163</td>\n",
       "      <td>4.928312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>8.442470</td>\n",
       "      <td>4.955827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>8.441607</td>\n",
       "      <td>5.000585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>8.486115</td>\n",
       "      <td>5.022234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>8.519790</td>\n",
       "      <td>5.022235</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     LnSales   LnPrice\n",
       "0   8.006368  4.765132\n",
       "1   8.113726  4.707727\n",
       "2   8.143227  4.707727\n",
       "3   8.196988  4.750396\n",
       "4   8.306472  4.750397\n",
       "5   8.434898  4.800839\n",
       "6   8.384576  4.844937\n",
       "7   8.406261  4.888373\n",
       "8   8.409163  4.928312\n",
       "9   8.442470  4.955827\n",
       "10  8.441607  5.000585\n",
       "11  8.486115  5.022234\n",
       "12  8.519790  5.022235"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Pr_Absolut"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> In order to find the impact of Price on sales,let's build a regression model on the dataset.\n",
    "  First let's plot some graphs to understand the data points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGG5JREFUeJzt3X2QXXd93/H3B8nFKweQwKKNxIMdaJU4mCLYJOYpuNiD\nCElsxZjUJCaYh7gkBBMDbvEkM6VOUpvIA4QkHXAJDyXYAVzhcZKC7MGhISU4XVlg2ThqCA+K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VH0vyKoCqege98aYX0PuixHeAlzXbhu79PlZe0SxJao3SmIIk\naZEMBUlSy1CQJLUMBUlSy1CQJLUMBY2sJN9awmNdluSeJB+Ytf7sJPc3s23ek+Q/zvH6DUluXJpq\npbn5lVSNrCTfqqofWKJj/S1wblXdO2v92cAbqupnkpwCfAb4t1V1x4w2q6vqgaWoU1qIZwpaUdK7\nL8JtzRz4H0/yuGb9E5qJ13Yn+e25zjKSvC7JXc3j15t176B3lfNHm4vejqqqvg3sBJ6Y5JIkNye5\nDfh4U9ddzf5WJbm2OcadSV7TrH9aMxnfziQ7mlk5pRPKUNBK8/vA+6rqycAHgLc3638P+L2qOpPe\nzJYPkuRp9K5c/Ql6Uxv8cpLNVfUqetNh/JuqeutcB25m/zwLuLtZ9VTgwqp6zqyml9K7f8NTputM\nclJT+4VV9TTg3fSmhZBOKENBK83T6d3wBeD9wLNmrP9ws3z97Bc1ngV8pKq+XVXfArYD/Uyh/exm\nFtBb6E3XMB0Kt84xBcK5wDunu5SaNpuAJwG3JvkM8Jv0JluTTqiRn/tIGgKfrKqfOcr6bx/DPgLc\nXVVPP0E1SUflmYJWmk/Rm1wQ4BeBTzbLnwZe2CxfNPtFjU8CW5OsaQaNf27G60+kW4F/l2Q1QJJH\nAnuA9Ume3qw7KcmPdnBsrXCGgkbZmiT3zni8jt6d1F6W5E7gJcBrm7a/DryuWf9E4P7ZO2u+MfRe\n4G+A24F3VdWuDup+F7AXuDPJZ4FfqKp/Ai4E3tys+wzwjA6OrRXOr6RKQJI1wFQzTfZFwIurarnc\nL1g6YRxTkHqeBvxBepPoHwBePuB6pIHwTEGS1HJMQZLUMhQkSS1DQZLUMhQkSS1DQZLUMhQkSa3/\nD6ZLXvy60NdaAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fa39b82ce90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(Pr_Absolut['LnPrice'],Pr_Absolut['LnSales'])\n",
    "plt.xlabel('Log of Price')\n",
    "plt.ylabel('Log of Sales')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> We can infer that price variation is almost linear in nature with sales."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import statsmodels.formula.api as sm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "result = sm.ols(formula = 'LnSales ~ LnPrice',data = Pr_Absolut).fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>OLS Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>LnSales</td>     <th>  R-squared:         </th> <td>   0.688</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                   <td>OLS</td>       <th>  Adj. R-squared:    </th> <td>   0.660</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   24.26</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>             <td>Sun, 04 Jun 2017</td> <th>  Prob (F-statistic):</th> <td>0.000453</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                 <td>14:19:16</td>     <th>  Log-Likelihood:    </th> <td>  13.282</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Observations:</th>      <td>    13</td>      <th>  AIC:               </th> <td>  -22.56</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Residuals:</th>          <td>    11</td>      <th>  BIC:               </th> <td>  -21.43</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Model:</th>              <td>     1</td>      <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th> <td>    2.8367</td> <td>    1.116</td> <td>    2.543</td> <td> 0.027</td> <td>    0.381     5.292</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnPrice</th>   <td>    1.1310</td> <td>    0.230</td> <td>    4.926</td> <td> 0.000</td> <td>    0.626     1.636</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Omnibus:</th>       <td> 4.580</td> <th>  Durbin-Watson:     </th> <td>   0.653</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Omnibus):</th> <td> 0.101</td> <th>  Jarque-Bera (JB):  </th> <td>   1.653</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Skew:</th>          <td>-0.553</td> <th>  Prob(JB):          </th> <td>   0.438</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Kurtosis:</th>      <td> 4.352</td> <th>  Cond. No.          </th> <td>    215.</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                            OLS Regression Results                            \n",
       "==============================================================================\n",
       "Dep. Variable:                LnSales   R-squared:                       0.688\n",
       "Model:                            OLS   Adj. R-squared:                  0.660\n",
       "Method:                 Least Squares   F-statistic:                     24.26\n",
       "Date:                Sun, 04 Jun 2017   Prob (F-statistic):           0.000453\n",
       "Time:                        14:19:16   Log-Likelihood:                 13.282\n",
       "No. Observations:                  13   AIC:                            -22.56\n",
       "Df Residuals:                      11   BIC:                            -21.43\n",
       "Df Model:                           1                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
       "------------------------------------------------------------------------------\n",
       "Intercept      2.8367      1.116      2.543      0.027         0.381     5.292\n",
       "LnPrice        1.1310      0.230      4.926      0.000         0.626     1.636\n",
       "==============================================================================\n",
       "Omnibus:                        4.580   Durbin-Watson:                   0.653\n",
       "Prob(Omnibus):                  0.101   Jarque-Bera (JB):                1.653\n",
       "Skew:                          -0.553   Prob(JB):                        0.438\n",
       "Kurtosis:                       4.352   Cond. No.                         215.\n",
       "==============================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
       "\"\"\""
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Here, the p-value of the price is zero that indicates that price is significant indicator of sales.\n",
    "\n",
    "Here, the value of R-squared is 0.688 i.e the price variable indicates nearly 69% of the data points.\n",
    "The co-efficient of price tells that for every unit increase in price, there is 1.13 times increase in sales.\n",
    "\n",
    "Let's add more variables to the regression and see what happens with the R-squared."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Now let's try with the advertising and price column."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Ad_Absolut = Absolut[['LnSales','LnMag','LnNews','LnOut','LnBroad','LnPrint','LnPrice']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "result_ad = sm.ols('LnSales ~ LnMag + LnNews + LnOut + LnBroad + LnPrint + LnPrice',data=Ad_Absolut).fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>OLS Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>LnSales</td>     <th>  R-squared:         </th> <td>   0.933</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                   <td>OLS</td>       <th>  Adj. R-squared:    </th> <td>   0.866</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   13.96</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>             <td>Sun, 04 Jun 2017</td> <th>  Prob (F-statistic):</th>  <td>0.00270</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                 <td>14:28:55</td>     <th>  Log-Likelihood:    </th> <td>  23.293</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Observations:</th>      <td>    13</td>      <th>  AIC:               </th> <td>  -32.59</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Residuals:</th>          <td>     6</td>      <th>  BIC:               </th> <td>  -28.63</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Model:</th>              <td>     6</td>      <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th> <td>    1.6613</td> <td>    1.697</td> <td>    0.979</td> <td> 0.365</td> <td>   -2.491     5.814</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnMag</th>     <td>    0.0891</td> <td>    0.062</td> <td>    1.438</td> <td> 0.200</td> <td>   -0.062     0.241</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnNews</th>    <td>    0.0131</td> <td>    0.012</td> <td>    1.132</td> <td> 0.301</td> <td>   -0.015     0.042</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnOut</th>     <td>   -0.1219</td> <td>    0.106</td> <td>   -1.152</td> <td> 0.293</td> <td>   -0.381     0.137</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnBroad</th>   <td>    0.0328</td> <td>    0.023</td> <td>    1.413</td> <td> 0.207</td> <td>   -0.024     0.090</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnPrint</th>   <td>    0.1101</td> <td>    0.081</td> <td>    1.366</td> <td> 0.221</td> <td>   -0.087     0.307</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnPrice</th>   <td>    1.0968</td> <td>    0.253</td> <td>    4.332</td> <td> 0.005</td> <td>    0.477     1.716</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Omnibus:</th>       <td> 0.747</td> <th>  Durbin-Watson:     </th> <td>   1.648</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Omnibus):</th> <td> 0.688</td> <th>  Jarque-Bera (JB):  </th> <td>   0.610</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Skew:</th>          <td> 0.043</td> <th>  Prob(JB):          </th> <td>   0.737</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Kurtosis:</th>      <td> 1.942</td> <th>  Cond. No.          </th> <td>1.83e+03</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                            OLS Regression Results                            \n",
       "==============================================================================\n",
       "Dep. Variable:                LnSales   R-squared:                       0.933\n",
       "Model:                            OLS   Adj. R-squared:                  0.866\n",
       "Method:                 Least Squares   F-statistic:                     13.96\n",
       "Date:                Sun, 04 Jun 2017   Prob (F-statistic):            0.00270\n",
       "Time:                        14:28:55   Log-Likelihood:                 23.293\n",
       "No. Observations:                  13   AIC:                            -32.59\n",
       "Df Residuals:                       6   BIC:                            -28.63\n",
       "Df Model:                           6                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
       "------------------------------------------------------------------------------\n",
       "Intercept      1.6613      1.697      0.979      0.365        -2.491     5.814\n",
       "LnMag          0.0891      0.062      1.438      0.200        -0.062     0.241\n",
       "LnNews         0.0131      0.012      1.132      0.301        -0.015     0.042\n",
       "LnOut         -0.1219      0.106     -1.152      0.293        -0.381     0.137\n",
       "LnBroad        0.0328      0.023      1.413      0.207        -0.024     0.090\n",
       "LnPrint        0.1101      0.081      1.366      0.221        -0.087     0.307\n",
       "LnPrice        1.0968      0.253      4.332      0.005         0.477     1.716\n",
       "==============================================================================\n",
       "Omnibus:                        0.747   Durbin-Watson:                   1.648\n",
       "Prob(Omnibus):                  0.688   Jarque-Bera (JB):                0.610\n",
       "Skew:                           0.043   Prob(JB):                        0.737\n",
       "Kurtosis:                       1.942   Cond. No.                     1.83e+03\n",
       "==============================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
       "[2] The condition number is large, 1.83e+03. This might indicate that there are\n",
       "strong multicollinearity or other numerical problems.\n",
       "\"\"\""
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_ad.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The R-squared value has increased!.The model is able to explain 87% of the data points. But here the p-values of some variables are high which can be accounted due to interaction effect and some other factors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try out the interation effect method between variables broad and print"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "result_inter = sm.ols('LnSales ~ LnMag + LnNews + LnOut + LnBroad * LnPrint + LnPrice',data=Ad_Absolut).fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>OLS Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>LnSales</td>     <th>  R-squared:         </th> <td>   0.972</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                   <td>OLS</td>       <th>  Adj. R-squared:    </th> <td>   0.933</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   24.84</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>             <td>Sun, 04 Jun 2017</td> <th>  Prob (F-statistic):</th>  <td>0.00135</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                 <td>14:54:03</td>     <th>  Log-Likelihood:    </th> <td>  28.963</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Observations:</th>      <td>    13</td>      <th>  AIC:               </th> <td>  -41.93</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Residuals:</th>          <td>     5</td>      <th>  BIC:               </th> <td>  -37.41</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Model:</th>              <td>     7</td>      <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "         <td></td>            <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>       <td>   -8.2128</td> <td>    3.931</td> <td>   -2.089</td> <td> 0.091</td> <td>  -18.317     1.892</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnMag</th>           <td>   -0.0110</td> <td>    0.058</td> <td>   -0.190</td> <td> 0.857</td> <td>   -0.160     0.138</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnNews</th>          <td>   -0.0056</td> <td>    0.011</td> <td>   -0.515</td> <td> 0.628</td> <td>   -0.034     0.022</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnOut</th>           <td>    0.0426</td> <td>    0.097</td> <td>    0.437</td> <td> 0.680</td> <td>   -0.208     0.293</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnBroad</th>         <td>    1.6251</td> <td>    0.604</td> <td>    2.692</td> <td> 0.043</td> <td>    0.073     3.177</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnPrint</th>         <td>    1.2719</td> <td>    0.444</td> <td>    2.864</td> <td> 0.035</td> <td>    0.130     2.413</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnBroad:LnPrint</th> <td>   -0.1586</td> <td>    0.060</td> <td>   -2.638</td> <td> 0.046</td> <td>   -0.313    -0.004</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LnPrice</th>         <td>    0.6901</td> <td>    0.236</td> <td>    2.919</td> <td> 0.033</td> <td>    0.082     1.298</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Omnibus:</th>       <td> 1.382</td> <th>  Durbin-Watson:     </th> <td>   1.615</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Omnibus):</th> <td> 0.501</td> <th>  Jarque-Bera (JB):  </th> <td>   0.165</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Skew:</th>          <td>-0.211</td> <th>  Prob(JB):          </th> <td>   0.921</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Kurtosis:</th>      <td> 3.355</td> <th>  Cond. No.          </th> <td>1.94e+04</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                            OLS Regression Results                            \n",
       "==============================================================================\n",
       "Dep. Variable:                LnSales   R-squared:                       0.972\n",
       "Model:                            OLS   Adj. R-squared:                  0.933\n",
       "Method:                 Least Squares   F-statistic:                     24.84\n",
       "Date:                Sun, 04 Jun 2017   Prob (F-statistic):            0.00135\n",
       "Time:                        14:54:03   Log-Likelihood:                 28.963\n",
       "No. Observations:                  13   AIC:                            -41.93\n",
       "Df Residuals:                       5   BIC:                            -37.41\n",
       "Df Model:                           7                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "===================================================================================\n",
       "                      coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
       "-----------------------------------------------------------------------------------\n",
       "Intercept          -8.2128      3.931     -2.089      0.091       -18.317     1.892\n",
       "LnMag              -0.0110      0.058     -0.190      0.857        -0.160     0.138\n",
       "LnNews             -0.0056      0.011     -0.515      0.628        -0.034     0.022\n",
       "LnOut               0.0426      0.097      0.437      0.680        -0.208     0.293\n",
       "LnBroad             1.6251      0.604      2.692      0.043         0.073     3.177\n",
       "LnPrint             1.2719      0.444      2.864      0.035         0.130     2.413\n",
       "LnBroad:LnPrint    -0.1586      0.060     -2.638      0.046        -0.313    -0.004\n",
       "LnPrice             0.6901      0.236      2.919      0.033         0.082     1.298\n",
       "==============================================================================\n",
       "Omnibus:                        1.382   Durbin-Watson:                   1.615\n",
       "Prob(Omnibus):                  0.501   Jarque-Bera (JB):                0.165\n",
       "Skew:                          -0.211   Prob(JB):                        0.921\n",
       "Kurtosis:                       3.355   Cond. No.                     1.94e+04\n",
       "==============================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
       "[2] The condition number is large, 1.94e+04. This might indicate that there are\n",
       "strong multicollinearity or other numerical problems.\n",
       "\"\"\""
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_inter.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Boom! The results here are surprised. The presence of significant interaction indicates that the effect of one predictor variable on the response variable is different at different values of the other predictor variable.\n",
    "    Therefore,the individial effects of the predictors also include the effects of the co-efficients of the interaction terms.\n",
    "    The R-squared value has also increased indicating the model can explain most of the data points now."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
